<template>
  <div class="transaction-surveillance container pb">
    <p class="bread">
      <a href="#/lawyer-center/lawyer-order">订单管理</a>
    </p>
    <div class="bg-c-fff box-border">
      <h3 class="tm-title">法律服务</h3>
      <step :stepData="stepData" :stepNum="stepNum" @stepRouter="stepRouter"></step>
    </div>
    <div class="surveillance-title-box">
      <div class="surveillance-title">法律服务监控流程图</div>
      <div class="btn-box">
        <button type="button" class="white-button" @click="onMsgShow" v-show="this.state<=3||this.stage<4">发送消息</button>
      </div>
    </div>
    <div class="progress-box">
      <company-name-container :companyNames="companyNames"></company-name-container>
      <div class="line" :class="{center: companyNames.length===2}" :style="{height: (events.length+0.5)*90+60+'px'}">
        <div class="arrow"></div>
      </div>
      <event-item v-for="(item,index) in events" :key="index" :state="item.state" :totalSides="companyNames.length" :side="item.side" :currentSide="1" :content="item.content" :files="item.files" :eventId="item.id" :serviceId="id" :tradeType="'law'" @fileUploaded="getEvents" :allState="state"></event-item>
      <div class="submit-box" :class="{'tc': companyNames.length===2}">
        <p class="tc">交易完成</p>
      </div>
    </div>
    <vodal :show="msgShow" animation="zoom" :width="380" :height="280" @hide="msgShow = false">
      <div class="vodal-main vodal-box">
        <h2>发送消息</h2>
        <ul class="con">
          <li>消息内容：
            <textarea class="vt" placeholder="请输入消息内容，我们将发送给信宝相关工作人员处理" v-model="msgText"></textarea>
          </li>
          <li class="tc auto">
            <button class="blue-button" @click="onMsgSubmit">确认</button>
          </li>
        </ul>
      </div>
    </vodal>
  </div>
</template>
<script type="text/javascript">
import Step from '../components/Step'
import CompanyNameContainer from '../components/CompanyNameContainer'
import EventItem from '../components/EventItem'
export default {
  components: {
    Step,
    CompanyNameContainer,
    EventItem
  },
  data() {
    return {
      stepNum: 3,
      stepData: [{
        name: '创建新订单'
      }, {
        name: '客户确认'
      }, {
        name: '监控员绘制流程图'
      }, {
        name: '法律服务监控'
      }, {
        name: '服务完成'
      }],
      companyNames: [],
      events: [],
      msgShow: false,
      id: '',
      state: 0,
      msgText: ''
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this.getEvents()
  },
  methods: {
    getEvents() {
      this.$http.get('/legalService/read/detail', {
        params: {
          id: this.id
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.state = data.data.data.status
          this.stage = data.data.data.stage
          this.companyNames = [{ name: data.data.data.customerName }, { name: data.data.data.lawyerName + '律师' }]
          this.events = []
          data.data.data.eventList.forEach(item => {
            let event = {}
            event.content = item.content
            event.side = item.memberOrder
            event.state = item.status
            event.files = item.fileList || []
            event.index = item.order
            event.id = item.id
            this.events.push(event)
          })
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onMsgShow() {
      this.msgShow = true
    },
    onMsgSubmit() {
      if (!this.msgText) {
        this.$toasted.show('消息内容不能为空')
        return
      }
      this.$http.post('/message/send/message/byorder', {
        orderid: this.$route.query.id,
        orderType: 1,
        msgKind: 1,
        sendType: 2,
        msgContent: this.msgText
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('发送成功')
          this.msgShow = false
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    stepRouter(i, name) {
      if (i === 0 && this.state >= 1) {
        this.$router.push('/lawyer-establish?id=' + this.$route.query.id)
      }
      if (i === 1 && this.state >= 1) {
        this.$router.push('/lawyer-customert-confirm?id=' + this.$route.query.id)
      }
      if (i === 2 && this.state >= 2) {
        this.$router.push('/lawyer-mapping?id=' + this.$route.query.id)
      }
      if (i === 3 && this.state >= 3) {
        this.$router.push('/lawyer-monitor?id=' + this.$route.query.id)
      }
      if (i === 4 && this.state >= 4) {
        this.$router.push('/lawyer-finish?id=' + this.$route.query.id)
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.tm-title {
  line-height: 40px;
  padding-left: 35px;
  font-size: 14px;
  color: #282828;
  border-bottom: 1px solid #ddd;
}

.pb {
  padding-bottom: 70px;
}

.surveillance-title-box {
  position: relative;
  width: 100%;
  height: 40px;
  line-height: 40px;
  margin-top: 20px;
  border-bottom: 1px solid #ddd;
  background-color: #fff;
  text-align: center;
}

.surveillance-title {
  font-size: 14px;
  color: #282828;
}

.surveillance-title-box .btn-box {
  position: absolute;
  top: 0;
  right: 100px;
  font-size: 14px;
}

.surveillance-title-box .white-button {
  width: 100px;
  height: 30px;
  line-height: 30px;
  margin-left: 10px;
}

.progress-box {
  position: relative;
  width: 100%;
  background-color: #fff;
  overflow-x: auto;
}

.line {
  position: absolute;
  width: 2px;
  top: 0;
  left: 65px;
  margin-top: 10px;
  background-color: #cfcfcf;
}

.line.center {
  left: 50%;
}

.line .arrow {
  position: absolute;
  bottom: -10px;
  left: -7px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid #cfcfcf;
}

.submit-box {
  width: 100%;
  padding: 40px;
}

.submit-box button {
  width: 120px;
  height: 35px;
}

.vodal-box h2 {
  background-color: #d8e7ff;
  font-size: 14px;
  font-weight: bold;
  line-height: 40px;
  text-indent: 40px;
}

.vodal-box .con {
  margin: 15px 20px;
  padding: 13px 0 0 13px;
}

.vodal-box .con li {
  margin-bottom: 20px;
}

.vodal-box textarea {
  border: 1px solid #ddd;
  width: 240px;
  padding: 6px 10px;
  line-height: 20px;
  height: 120px;
}

.vodal-box button {
  margin: 0 15px;
  width: 120px;
  height: 35px;
}

</style>
